package com.m3958.firstgwt.server.model;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.eclipse.persistence.annotations.Cache;
import org.eclipse.persistence.config.CacheIsolationType;


import net.sf.json.JSONObject;
/*
 * 一个对象一天一条记录
 */
@Entity
@Cache(
		isolation =  CacheIsolationType.PROTECTED
	)
@Table(name="PAGE_HIT_DETAIL")
@AttributeOverride(name="id",column=@Column(nullable = false,name="PAGE_HIT_DETAIL_ID"))
@NamedQueries({
	@NamedQuery(name="pageHitDetail_findPageHitCount",
			query="SELECT COUNT(DISTINCT p) FROM PageHitDetail AS p WHERE p.urlstat = :urlstat"),
	@NamedQuery(name="pageHitDetail_sincePageHitCount",
			query="SELECT COUNT(DISTINCT p) FROM PageHitDetail AS p WHERE p.urlstat = :urlstat"),
	@NamedQuery(name="pageHitDetail_findSiteHitCount",
			query="SELECT COUNT(DISTINCT p) FROM PageHitDetail AS p WHERE p.urlstat.siteId = :siteId"),
	@NamedQuery(name="pageHitDetail_sinceSiteHitCount",
			query="SELECT COUNT(DISTINCT p) FROM PageHitDetail AS p WHERE p.urlstat.siteId = :siteId AND p.createdAt > :startTime")

})
public class PageHitDetail extends BaseModel<PageHitDetail>{
	
	public static class NamedQueries{
		public final static String FIND_PAGE_HITCOUNT = "pageHitDetail_findPageHitCount";
		public final static String FIND_SITE_HITCOUNT = "pageHitDetail_findSiteHitCount";
		public final static String SINCE_SITE_HITCOUNT = "pageHitDetail_sinceSiteHitCount";
		public final static String SINCE_PAGE_HITCOUNT = "pageHitDetail_sincePageHitCount";
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="URL_STAT_ID",referencedColumnName="URL_STAT_ID")
	private UrlStatistics urlstat;
	
	private String cat1;
	
	private String cat2;
	
	private String cat3;
	
	@Column(length=40)
	private String obname;
	
	@Column(length=40)
	private String obId;
	
	private long ip;

	public String getObId() {
		return obId;
	}

	public void setObId(String obId) {
		this.obId = obId;
	}

	@Override
	public JSONObject toJson() {
		return null;
	}

	public void setObname(String obname) {
		this.obname = obname;
	}

	public String getObname() {
		return obname;
	}

	public void setIp(long ip) {
		this.ip = ip;
	}

	public long getIp() {
		return ip;
	}

	public void setCat1(String cat1) {
		this.cat1 = cat1;
	}

	public String getCat1() {
		return cat1;
	}

	public void setCat2(String cat2) {
		this.cat2 = cat2;
	}

	public String getCat2() {
		return cat2;
	}

	public void setCat3(String cat3) {
		this.cat3 = cat3;
	}

	public String getCat3() {
		return cat3;
	}

	public void setUrlstat(UrlStatistics urlstat) {
		this.urlstat = urlstat;
	}

	public UrlStatistics getUrlstat() {
		return urlstat;
	}

	@Override
	public String[] getJsonExcludes() {
		// TODO Auto-generated method stub
		return null;
	}
}
